package cn.jxufe.controller;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jxufe.bean.ChatUser;
import cn.jxufe.bean.Message;
import cn.jxufe.bean.Talk;
import cn.jxufe.service.ChatService;
/***
 * websocket建立连接
 * @author Banner
 *
 */
@Controller
@RequestMapping("action")
public class ChatController {
	@Autowired
	ChatService chatService;
	/***
	 * 设置当前的在线的用户，模拟登录时调用.
	 * @param session 请求
	 * @param chatUser 已连接用户
	 * @return Message 消息实体
	 */
	@RequestMapping(value="setCurUser",produces=MediaType.APPLICATION_JSON_VALUE,consumes =MediaType.APPLICATION_JSON_VALUE )
	@ResponseBody
	public Message setCurUser(HttpSession session, @RequestBody ChatUser chatUser){			
		return chatService.setCurUser(session, chatUser);
	}
	
	@RequestMapping(value="talk",produces=MediaType.APPLICATION_JSON_VALUE,consumes =MediaType.APPLICATION_JSON_VALUE )
	@ResponseBody
	public Message talk(HttpSession session, @RequestBody Talk talk){	
		return chatService.talk(session, talk);
	}
}
